home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / hobbes3 / bitblts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-17  |  2.7 KB  |  79 lines

  1. #include <alloc.h>
  2. #include "hobbes.h"
  3.  
  4.  
  5. void CreateAlignedMaskedImage(MaskedImage *ImageToSet, char *Image,
  6.         int ImageWidth,    int ImageHeight, char *Mask) {
  7.     VRAM_PTR DispMemStart = Bitmap_Offset;
  8.  
  9.    int Align, ScanLine, BitNum, Size, TempImageWidth;
  10.    unsigned char MaskTemp;
  11.    unsigned int DispMemOffset = DispMemStart;
  12.    AlignedMaskedImage *WorkingAMImage;
  13.    char *NewMaskPtr, *OldMaskPtr;
  14.    /* Generate each of the four alignments in turn */
  15.    for (Align = 0; Align < 4; Align++) {
  16.       /* Allocate space for the AlignedMaskedImage struct for this
  17.          alignment */
  18.       if ((WorkingAMImage = ImageToSet->Alignments[Align] = (AlignedMaskedImage*)
  19.             malloc(sizeof(AlignedMaskedImage))) == NULL)
  20.          return;
  21.       WorkingAMImage->ImageWidth =
  22.             (ImageWidth + Align + 3) / 4; /* width in 4-pixel sets */
  23.       WorkingAMImage->ImagePtr = DispMemOffset; /* image dest */
  24.       /* Download this alignment of the image */
  25.       CopySystemToScreen(0, 0, ImageWidth, ImageHeight, Align, 0,
  26.             Image, DispMemOffset, ImageWidth,
  27.             WorkingAMImage->ImageWidth * 4);
  28.       /* Calculate the number of bytes needed to store the mask in
  29.          nibble (Map Mask-ready) form, then allocate that space */
  30.       Size = WorkingAMImage->ImageWidth * ImageHeight;
  31.       if ((WorkingAMImage->MaskPtr = (char*) malloc(Size)) == NULL)
  32.          return;
  33.       /* Generate this nibble oriented (Map Mask-ready) alignment of
  34.          the mask, one scan line at a time */
  35.       OldMaskPtr = Mask;
  36.       NewMaskPtr = WorkingAMImage->MaskPtr;
  37.       for (ScanLine = 0; ScanLine < ImageHeight; ScanLine++) {
  38.          BitNum = Align;
  39.          MaskTemp = 0;
  40.          TempImageWidth = ImageWidth;
  41.          do {
  42.             /* Set the mask bit for next pixel according to its alignment */
  43.             MaskTemp |= (*OldMaskPtr++ != 0) << BitNum;
  44.             if (++BitNum > 3) {
  45.                *NewMaskPtr++ = MaskTemp;
  46.                MaskTemp = BitNum = 0;
  47.             }
  48.          } while (--TempImageWidth);
  49.          /* Set any partial final mask on this scan line */
  50.          if (BitNum != 0) *NewMaskPtr++ = MaskTemp;
  51.       }
  52.       DispMemOffset += Size; /* mark off the space we just used */
  53.    }
  54. //   return DispMemOffset - DispMemStart;
  55.    Bitmap_Offset += (DispMemOffset - DispMemStart);
  56. }
  57.  
  58. void CopyScreenToScreenMasked(int SourceStartX, int SourceStartY,
  59.     int SourceEndX, int SourceEndY,    int DestStartX, int DestStartY,
  60.     MaskedImage *Source, VRAM_PTR DestPageBase, int DestWidth) {
  61.  
  62.     int psi, imagewidth;
  63.     VRAM_PTR imageptr;
  64.     char *maskptr;
  65.  
  66.  
  67.     psi = DestStartX & 3;
  68.     imagewidth =     (Source->Alignments[psi])->ImageWidth;
  69.     imageptr =         (Source->Alignments[psi])->ImagePtr;
  70.     maskptr =         (Source->Alignments[psi])->MaskPtr;
  71.  
  72.     CopyScreenToScreenMaskedX(SourceStartX, SourceStartY,
  73.                 SourceEndX, SourceEndY,
  74.                 DestStartX, DestStartY,
  75.                 imagewidth, imageptr, maskptr);
  76. }
  77.  
  78.  
  79.